package com.oracle.manager.web;

import com.oracle.beans.CheckItem;
import com.oracle.beans.PageBean;
import com.oracle.beans.QueryPageVo;
import com.oracle.beans.ResultInfo;
import com.oracle.manager.service.feign.CheckItemFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestClientException;


@RestController
@RequestMapping("/manager/checkItem")
@Slf4j
public class CheckItemController {

    @Autowired
    CheckItemFeignClient checkItemFeignClient;

    @GetMapping("findList")
    public ResultInfo findList( QueryPageVo vo){

        PageBean<CheckItem> pageBean = checkItemFeignClient.findList(vo.getCurrentPage(),vo.getPageSize()
        ,vo.getQueryString());
        return new ResultInfo(true,"",pageBean);
    }

    @PostMapping("add")
    public ResultInfo add(@RequestBody CheckItem checkItem){
        log.warn(checkItem.toString());
        ResultInfo info = checkItemFeignClient.add(checkItem);
        return info;
    }

    @PutMapping("update")
    public ResultInfo update(@RequestBody CheckItem checkItem){
        log.warn(checkItem.toString());
        try {
            checkItemFeignClient.update(checkItem);
            return new ResultInfo(true,"修改成功",null);
        } catch (RestClientException e) {
            e.printStackTrace();
            return new ResultInfo(false,"修改失败",null);
        }
    }

    @DeleteMapping("delete/{id}")
    public ResultInfo delete(@PathVariable("id") Integer id){
        log.warn(id+"");
        try {
           checkItemFeignClient.delete(id);
            return new ResultInfo(true,"删除检查项成功",null);
        }catch (RestClientException e){
            e.printStackTrace();
            return new ResultInfo(false,"删除检查项失败",null);
        }
    }

    @GetMapping("findAll")
    public ResultInfo findAll(){
        ResultInfo resultInfo = checkItemFeignClient.findAll();
        return resultInfo;
    }

}
